glimpse(lodesresidents)
## Rows: 155
## Columns: 14
## $ blkgroup <dbl> 510030101001, 510030101002, 510030101003, 5100301…
## $ medc_allblk <dbl> 24.17281, 34.11035, 29.70686, 22.44022, 17.74491,…
## $ medc_workinRegionblk <dbl> 5.269266, 11.406913, 9.025905, 5.388651, 3.464939…
## $ medc_within40blk <dbl> 7.443729, 12.420517, 10.480196, 7.207290, 5.55071…
## $ medc_25_employeesblk <dbl> 19.67874, 25.85719, 21.31691, 16.49003, 13.16050,…
## $ commutersInBlgr <int> 822, 666, 636, 1396, 991, 706, 771, 1066, 405, 68…
## $ commuterinRegionblk <int> 576, 447, 437, 1028, 767, 531, 602, 803, 312, 507…
## $ commuterw40blk <int> 643, 497, 489, 1124, 843, 571, 637, 873, 333, 551…
## $ commuter25blk <int> 750, 615, 583, 1299, 941, 659, 730, 1001, 380, 63…
## $ avgc_allblk <dbl> 26.56419, 32.68364, 29.94505, 22.19963, 16.95999,…
## $ avgc_workinRegionblk <dbl> 5.248561, 11.585876, 8.421038, 6.016676, 3.582384…
## $ avgc_within40blk <dbl> 7.401903, 12.448308, 10.004912, 7.713104, 5.54740…
## $ avgc_25_employeesblk <dbl> 18.84796, 27.83559, 22.77203, 17.17362, 13.14508,…
## $ county <int> 51003, 51003, 51003, 51003, 51003, 51003, 51003, …
glimpse(lodesworkers)
## Rows: 155
## Columns: 15
## $ blkgroup <dbl> 510030101001, 510030101002, 510030…
## $ medc_allworkersblkgr <dbl> 12.09504, 14.50409, 13.17269, 50.6…
## $ medc_livewithin40blkgr <dbl> 8.611876, 12.103952, 9.827892, 7.9…
## $ medc_25_resblkgr <dbl> 9.628765, 13.635415, 13.172687, 18…
## $ workersInblkgr <int> 140, 214, 166, 339, 420, 106, 225,…
## $ liveoutsideCvilleblkgr <int> 25, 32, 35, 177, 207, 38, 82, 201,…
## $ liveinsideCvilleblkgr <int> 115, 182, 131, 162, 213, 68, 143, …
## $ perc_workers_liveinCvilleblkgr <dbl> 82.14286, 85.04673, 78.91566, 47.7…
## $ perc_workers_liveoutsideCvilleblkgr <dbl> 17.85714, 14.95327, 21.08434, 52.2…
## $ workersw40blkgr <int> 129, 202, 156, 197, 258, 90, 182, …
## $ workers25blkgr <int> 137, 209, 163, 229, 319, 102, 203,…
## $ avgc_allworkersblkgr <dbl> 14.05530, 14.26546, 14.05853, 40.3…
## $ avgc_livewithin40blkgr <dbl> 9.480085, 11.328362, 10.386598, 8.…
## $ avgc_25_resblkgr <dbl> 12.19015, 12.72519, 12.84469, 17.1…
## $ county <int> 51003, 51003, 51003, 51003, 51003,…
metaresidents %>%
filter(su_blkgp == 1) %>%
select(varname, about) %>% as.list()
## $varname
## [1] "blkgroup" "county" "avgc_allblk"
## [4] "medc_allblk" "commutersInBlgr" "avgc_within40blk"
## [7] "medc_within40blk" "commuterw40blk" "avgc_25_employeesblk"
## [10] "medc_25_employeesblk" "commuter25blk" "avgc_workinRegionblk"
## [13] "medc_workinRegionblk" "commuterinRegionblk"
##
## $about
## [1] "12-digit census block group code"
## [2] "5-digit county code"
## [3] "Average \"as the crow flies\" commuting distance for all residents of the census block group"
## [4] "Median \"as the crow flies\" commuting distance for all residents of the census block group"
## [5] "The number of residents in each census block group who are represented in the data"
## [6] "Average \"as the crow flies\" commuting distance for residents of the census block group who work within 40 miles"
## [7] "Median \"as the crow flies\" commuting distance for residents of the census block group who work within 40 miles"
## [8] "The number of residents in the census block group who work within 40 miles of home"
## [9] "Average \"as the crow flies\" commuting distance for residents of the census block group who commute to a census tract that employs at least 25 residents from the region of interest"
## [10] "Median \"as the crow flies\" commuting distance for residents of the census block group who commute to a census tract that employs at least 25 residents of the region of interest"
## [11] "The number of residents in the census block group who commute to a census tract that employs at least 25 residents of the region of interest"
## [12] "Average \"as the crow flies\" commuting distance for residents of the census block group who work in the same region as where they live"
## [13] "Median \"as the crow flies\" commuting distance for residents of the census block group who work in the same region as where they live"
## [14] "The number of residents in the census block group who commute to work within the region of interest"
metaworkers %>%
filter(su_blkgp == 1) %>%
select(varname, about) %>% as.list()
## $varname
## [1] "blkgroup" "medc_allworkersblkgr"
## [3] "medc_livewithin40blkgr" "medc_25_resblkgr"
## [5] "workersInblkgr" "liveoutsideCvilleblkgr"
## [7] "liveinsideCvilleblkgr" "perc_workers_liveinCvilleblkgr"
## [9] "perc_workers_liveoutsideCvilleblkgr" "workersw40blkgr"
## [11] "workers25blkgr" "avgc_allworkersblkgr"
## [13] "avgc_livewithin40blkgr" "avgc_25_resblkgr"
## [15] "county"
##
## $about
## [1] "12-digit census block group code where the workers are employed (workplace census block group)"
## [2] "Median \"as the crow flies\" commuting distance for all workers employed in the census block group"
## [3] "Median \"as the crow flies\" commuting distance for workers employed in the census block group who live within 40 miles of work"
## [4] "Median \"as the crow flies\" commute for workers employed in the census block group who live in census tract where at least 25 Charlottesville region workers live"
## [5] "The total number of workers employed in the census block group"
## [6] "The number of workers employed in the census block group that live outside the Charlottesville region"
## [7] "The number of workers employed in the census block group who live outside the Charlottesville region"
## [8] "The percent of workers employed in the census block group who live inside the Charlottesville region"
## [9] "The percent of workers employed in the census block group who live outside the Charlottesville region"
## [10] "The number of workers employed in the census block group who live within 40 miles of work"
## [11] "The number of workers employed in the census block group who live in a census tract where at least 25 Charlottesville region workers live"
## [12] "Average \"as the crow flies\" commuting distance for all workers employed in the census block group"
## [13] "Average \"as the crow flies\" commuting distance for workers employed in the census block group who live within 40 miles of work"
## [14] "Average \"as the crow flies\" commute for workers employed in the census block group who live in census tract where at least 25 Charlottesville region workers live"
## [15] "5-digit county code"
lodesresidents %>% select(avgc_allblk, avgc_within40blk, avgc_25_employeesblk, avgc_workinRegionblk, medc_allblk, medc_within40blk, medc_25_employeesblk, medc_workinRegionblk) %>%
select(where(~is.numeric(.x))) %>%
as.data.frame() %>%
stargazer(., type = "text", title = "Summary Statistics", digits = 2,
summary.stat = c("mean", "sd", "min", "median", "max"))
##
## Summary Statistics
## ======================================================
## Statistic Mean St. Dev. Min Median Max
## ------------------------------------------------------
## avgc_allblk 25.39 8.69 13.25 24.31 78.38
## avgc_within40blk 9.13 5.10 3.07 7.39 22.56
## avgc_25_employeesblk 19.89 7.67 9.36 18.78 64.84
## avgc_workinRegionblk 7.71 5.91 1.36 5.33 24.26
## medc_allblk 25.15 9.05 12.83 23.88 78.87
## medc_within40blk 9.12 5.15 2.76 7.21 22.77
## medc_25_employeesblk 19.56 7.93 8.30 18.41 69.65
## medc_workinRegionblk 7.63 5.87 1.15 5.20 24.28
## ------------------------------------------------------
lodesworkers %>% select(avgc_allworkersblkgr, avgc_livewithin40blkgr, avgc_25_resblkgr, medc_allworkersblkgr, medc_livewithin40blkgr, medc_25_resblkgr, perc_workers_liveoutsideCvilleblkgr) %>%
select(where(~is.numeric(.x))) %>%
as.data.frame() %>%
stargazer(., type = "text", title = "Summary Statistics", digits = 2,
summary.stat = c("mean", "sd", "min", "median", "max"))
##
## Summary Statistics
## =====================================================================
## Statistic Mean St. Dev. Min Median Max
## ---------------------------------------------------------------------
## avgc_allworkersblkgr 25.22 8.13 9.36 24.09 48.44
## avgc_livewithin40blkgr 10.58 2.18 3.42 10.65 17.68
## avgc_25_resblkgr 15.76 3.96 7.03 15.22 30.87
## medc_allworkersblkgr 24.50 9.81 4.67 23.07 52.42
## medc_livewithin40blkgr 10.54 2.43 3.50 10.50 18.37
## medc_25_resblkgr 15.42 4.60 4.67 14.97 34.52
## perc_workers_liveoutsideCvilleblkgr 36.10 11.34 14.50 35.85 77.70
## ---------------------------------------------------------------------
longr <- lodesresidents %>% select(c(blkgroup, avgc_allblk, avgc_within40blk, avgc_25_employeesblk, avgc_workinRegionblk, medc_allblk, medc_within40blk, medc_25_employeesblk, medc_workinRegionblk)) %>%
pivot_longer(-blkgroup, names_to = "measure", values_to = "value")
longr$measure <- factor(longr$measure,
levels = c("avgc_allblk", "medc_allblk", "avgc_within40blk", "medc_within40blk", "avgc_25_employeesblk", "medc_25_employeesblk", "avgc_workinRegionblk",
"medc_workinRegionblk"))
longr %>%
ggplot(aes(x = value, fill = measure)) +
scale_fill_viridis(option = "plasma", discrete = TRUE, guide = FALSE) +
geom_histogram() +
facet_wrap(~measure, scales = "free", ncol = 2)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
longw <- lodesworkers %>% select(c(blkgroup, avgc_allworkersblkgr, avgc_livewithin40blkgr, avgc_25_resblkgr, medc_allworkersblkgr, medc_livewithin40blkgr, medc_25_resblkgr)) %>%
pivot_longer(-blkgroup, names_to = "measure", values_to = "value")
longw$measure <- factor(longw$measure,
levels = c("avgc_allworkersblkgr", "medc_allworkersblkgr", "avgc_livewithin40blkgr", "medc_livewithin40blkgr", "avgc_25_resblkgr", "medc_25_resblkgr"))
longw %>%
ggplot(aes(x = value, fill = measure)) +
scale_fill_viridis(option = "plasma", discrete = TRUE, guide = FALSE) +
geom_histogram() +
facet_wrap(~measure, scales = "free", ncol = 2)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodesfull$avgc_allblk)
leaflet(cvl_lodesfull) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodesfull,
fillColor = ~pal(avgc_allblk),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodesfull$geocode, "<br>",
"Average commute (mi): ", round(cvl_lodesfull$avgc_allblk, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodesfull$avgc_allblk,
title = "Average commute (mi)", opacity = 0.7)
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodesfull$avgc_allworkersblkgr)
leaflet(cvl_lodesfull) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodesfull,
fillColor = ~pal(avgc_allworkersblkgr),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodesfull$geocode, "<br>",
"Average commute (mi): ", round(cvl_lodesfull$avgc_allworkersblkgr, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodesfull$avgc_allworkersblkgr,
title = "Average commute (mi)", opacity = 0.7)
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodesfull$avgc_within40blk)
leaflet(cvl_lodesfull) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodesfull,
fillColor = ~pal(avgc_within40blk),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodesfull$geocode, "<br>",
"Average commute (mi): ", round(cvl_lodesfull$avgc_within40blk, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodesfull$avgc_within40blk,
title = "Average commute (mi)", opacity = 0.7)
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodesfull$avgc_livewithin40blkgr)
leaflet(cvl_lodesfull) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodesfull,
fillColor = ~pal(avgc_livewithin40blkgr),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodesfull$geocode, "<br>",
"Average commute (mi): ", round(cvl_lodesfull$avgc_livewithin40blkgr, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodesfull$avgc_livewithin40blkgr,
title = "Average commute (mi)", opacity = 0.7)
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodesfull$avgc_workinRegionblk)
leaflet(cvl_lodesfull) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodesfull,
fillColor = ~pal(avgc_workinRegionblk),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodesfull$geocode, "<br>",
"Average commute (mi): ", round(cvl_lodesfull$avgc_workinRegionblk, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodesfull$avgc_workinRegionblk,
title = "Average commute (mi)", opacity = 0.7)
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodesfull$perc_workers_liveoutsideCvilleblkgr)
leaflet(cvl_lodesfull) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodesfull,
fillColor = ~pal(perc_workers_liveoutsideCvilleblkgr),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodesfull$geocode, "<br>",
"Percent of workers: ", round(cvl_lodesfull$perc_workers_liveoutsideCvilleblkgr, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodesfull$perc_workers_liveoutsideCvilleblkgr,
title = "Percent of workers <br> who live outside Cville <br> region", opacity = 0.7)